package cn.hunau.bookstore.admin.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.hunau.bookstore.pojo.ResponseResult;
import cn.hunau.bookstore.service.AdminService;
import cn.hunau.bookstore.service.impl.AdminServiceImpl;
import cn.hunau.bookstore.utils.JsonUtils;

/**
 * @author HuangBo
 *
 *         2022-01-18 15:56:14
 *
 */
@MultipartConfig
@WebServlet("/admin/login")
public class AdminController extends HttpServlet {
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		AdminService adminService = new AdminServiceImpl();

		String email = request.getParameter("email"); 
		String password = request.getParameter("password");
        System.out.println(email+":"+password);
		ResponseResult result = adminService.login(email, password);
		if(result.isFlag()) {
		   HttpSession session=request.getSession();
		   session.setAttribute("admin", result);
		}
		out.println(JsonUtils.objectToJson(result));
	}
}
